package com.wing.user.service;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wing.common.utils.JsonResult;
import com.wing.user.dao.WarehouseUserDao;
import com.wing.user.model.entity.WarehouseCustomer;
import com.wing.warehouse.model.response.WarehouseUserAuthVO;
import org.springframework.stereotype.Service;
import com.wing.user.model.entity.WarehouseUser;

import java.util.Map;

@Service
public class WarehouseUserServiceImpl extends ServiceImpl<WarehouseUserDao, WarehouseUser> implements WarehouseUserService{

    @Override
    public WarehouseUserAuthVO getByUsername(String account) {
        return baseMapper.getByUsername(account);
    }

    @Override
    public Page<WarehouseUser> pageList4app(Page<WarehouseUser> pg, Map paramMap) {
        return baseMapper.pageList4app(pg, paramMap);

    }

    @Override
    public int add(WarehouseUser warehouseUser){
        if (ObjectUtil.isNotEmpty(warehouseUser)){
            return baseMapper.insert(warehouseUser);
        }else {
            return 0;
        }
    }

    @Override
    public JsonResult updateWarehouseUser(WarehouseUser warehouseUser){
        JsonResult jsonResult = new JsonResult<>();
        if (warehouseUser.getId() != null){
            baseMapper.updateById(warehouseUser);
            return jsonResult.success("修改成功");
        }else {
            return jsonResult.fail("修改失败");
        }
    }

    @Override
    public JsonResult deleteWarehouseUser(Long warehouseUserId){
        JsonResult jsonResult = new JsonResult<>();
        if (warehouseUserId != null){
            WarehouseUser warehouseUser = this.getById(warehouseUserId);
            warehouseUser.setIsDeleted(true);
            this.updateById(warehouseUser);
            return jsonResult.success("删除成功");
        }else {
            return jsonResult.fail("删除失败");
        }
    }
}
